package com.hbx.staservice.schedule;

import com.hbx.staservice.service.StatisticsDailyService;
import com.hbx.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/** 定时任务所需的类
 * @Author hbx
 * @Date 2023/10/22 15:03
 */
@Component
public class ScheduledTask {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    // 在线生成cron表达式  http://cron.qqe2.com/

    //在每天凌晨12点，把前一天的数据进行生成
    @Scheduled(cron = "0 0 0 * * ?")
    public void task(){
        //DateUtil为工具类
        statisticsDailyService.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(),-1)));
    }
}
